﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MikroObject
{
    public class ExtensionMethods
    {
        public static string DateToString(DateTime tarih)
        {
            return string.Format("{0}-{1}-{2} {3}:{4}:{5}", tarih.Year, tarih.Month.ToString("00"), tarih.Day.ToString("00"), tarih.Hour.ToString("00"), tarih.Minute.ToString("00"), tarih.Second.ToString("00"));
        }
        public static string DateToString2(DateTime tarih)
        {
            return string.Format("{0}-{1}-{2} 00:00:00", tarih.Year, tarih.Month.ToString("00"), tarih.Day.ToString("00"));
        }
        public static string Mid(string str, int Start, int Length)
        {
            if (Start <= 0)
            {
                throw new ArgumentException("Argument_GTZero1");
            }
            if (Length < 0)
            {
                throw new ArgumentException("Argument_GEZero1");
            }
            if ((Length == 0) || (str == null))
            {
                return "";
            }
            int length = str.Length;
            if (Start > length)
            {
                return "";
            }
            if ((Start + Length) > length)
            {
                return str.Substring(Start - 1);
            }
            return str.Substring(Start - 1, Length);
        }
        public static decimal Cevir(object deger)
        {
            if (deger != null && deger != DBNull.Value)
            {
                return Convert.ToDecimal(deger);
            }
            else
                return 0;
        }
        public static DateTime ParseDate(string date)
        {
            string[] t1 = date.Split(' ')[0].Split('-');
            string[] t2 = date.Split(' ')[1].Split(':');
            return new DateTime(int.Parse(t1[0]), int.Parse(t1[1]), int.Parse(t1[2]), int.Parse(t2[0]), int.Parse(t2[1]), int.Parse(t2[2]));
        }
    }
}
